package com.lagou;

import com.lagou.bean.Resume;
import com.lagou.repository.ResumeRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

import java.util.Date;
import java.util.List;

@SpringBootApplication
public class MongoRepositoryMain {

    private static ResumeRepository resumeRepository;


    public static void testAdd() {

        String[] cities = new String[]{"上海", "北京", "杭州", "深圳", "广州"};

        for (int i = 1; i <= 200; i++) {
            Resume resume = new Resume();
            resume.setName("test" + i);
            resume.setBirthday(new Date());
            resume.setCity(cities[(int)(Math.random() * cities.length)]);
            resume.setExpectSalary(10000 + (int)(6 * Math.random()) * 5000);
            System.out.println("write " + i);

            resumeRepository.insert(resume);
        }
    }

    public static void testRead() {
        List<Resume> resumes = resumeRepository.findAll();
        System.out.println("========> size = " + resumes.size());
        for (Resume resume : resumes) {
            System.out.println(resume);
        }

    }

    public static void testRemove() {
        resumeRepository.deleteAll();
    }


    public static void main(String[] args) {
        ApplicationContext applicationContext = SpringApplication.run(MongoRepositoryMain.class, args);

        resumeRepository = applicationContext.getBean(ResumeRepository.class);

//        testAdd();
        testRead();
//        testRemove();
    }
}
